<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 使⽤ JS 闭包，给 10 个 p 标签循环加上点击事件 -->
</head>
<body>
  <script>
     function num(){
      let ps = []
      for(let i = 0; i < 10; i++){
        ps.push(document.createElement('p'))
      }
      function str(){
        for(let i = 0; i < ps.length; i++){
          // let p = document.createElement('p');
          let p = ps[i]
          p.innerHTML = '标签' + i
          document.body.appendChild(p)
          p.onclick = function(){
            alert('标签' + i)
          }
        }
      }
      return str()
     }
     num()
  </script>
</body>
</html>